//  TODO: if you use this file, remove my comments to you and add
//        comments of your own
//
//  An example user-level program that makes a call to the 
//  getcurrenttime system call
//
//  You can use this as a starting point for impelmenting test program(s)
//  to test your system calls. 
//
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <time.h>
#include <sys/syscall.h>
#include <asm/unistd.h>

// TODO: if you add header files to the kernel that user-level code needs to
// include, make sure to add those here.  For example:
// #include <linux/my_header_file.h>


// TODO: define a macro for your system call, using its number directly
//#define getcurrenttime(flag, tval) syscall(299, flag, tval)
// or better yet, using its __NR_ definition (this is why the second
// -I path in the makefile is needed):
#define getcurrenttime(flag, tval) syscall(__NR_getcurrenttime, flag, tval)

// with the macro definition, user-level code can call 'getcurrenttime'
// instead of syscall(number, param1, param2, ...)

main() {

  struct timespec tval; 
  int ret;

  // This is common C shorthand for assigning the return value of a 
  // function to a variable and then evaluating that return value:
  //   (1) ret gets return value from call
  //   (2) the value of ret is evaluated 
  // It is equivalent to these two statements:
  //   ret = getcurrenttime(1,&tval);
  //   if(ret) { ... }   // or if(ret != 0) 
  if(ret=getcurrenttime(1,&tval)) {  
    perror("getcurrenttime\n");
    exit(1);
  }
  printf("time = %ld %ld\n", tval.tv_sec, tval.tv_nsec);
  printf("%s\n", ctime(&(tval.tv_sec)));
}
